<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.14"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>FabGL: SSD1306_OLED/128x64/RTClock/RTClock.ino</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  $(document).ready(initResizable);
/* @license-end */</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">FabGL
   </div>
   <div id="projectbrief">ESP32 Display Controller and Graphics Library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.14 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('_s_s_d1306__o_l_e_d_2128x64_2_r_t_clock_2_r_t_clock_8ino-example.html','');});
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">SSD1306_OLED/128x64/RTClock/RTClock.ino</div>  </div>
</div><!--header-->
<div class="contents">
<p>DateTime clock using DS3231 RTC</p>
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment">  Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - www.fabgl.com</span></div><div class="line"><span class="comment">  Copyright (c) 2019-2020 Fabrizio Di Vittorio.</span></div><div class="line"><span class="comment">  All rights reserved.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  This file is part of FabGL Library.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  FabGL is free software: you can redistribute it and/or modify</span></div><div class="line"><span class="comment">  it under the terms of the GNU General Public License as published by</span></div><div class="line"><span class="comment">  the Free Software Foundation, either version 3 of the License, or</span></div><div class="line"><span class="comment">  (at your option) any later version.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  FabGL is distributed in the hope that it will be useful,</span></div><div class="line"><span class="comment">  but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div><div class="line"><span class="comment">  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span></div><div class="line"><span class="comment">  GNU General Public License for more details.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  You should have received a copy of the GNU General Public License</span></div><div class="line"><span class="comment">  along with FabGL.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * OLED and DS3231 - SDA =&gt; GPIO 4</span></div><div class="line"><span class="comment"> * OLED and DS3231 - SCL =&gt; GPIO 15</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="fabgl_8h.html">fabgl.h</a>&quot;</span></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="preprocessor">#define OLED_SDA       GPIO_NUM_4</span></div><div class="line"><span class="preprocessor">#define OLED_SCL       GPIO_NUM_15</span></div><div class="line"><span class="preprocessor">#define OLED_ADDR      0x3C</span></div><div class="line"></div><div class="line"><span class="comment">// if your display hasn&#39;t RESET set to GPIO_UNUSED</span></div><div class="line"><span class="preprocessor">#define OLED_RESET     GPIO_UNUSED  // ie Heltec has GPIO_NUM_16 for reset</span></div><div class="line"></div><div class="line"><span class="preprocessor">#define DS3231_ADDR    0x68</span></div><div class="line"></div><div class="line"></div><div class="line"><a name="_a0"></a><a class="code" href="classfabgl_1_1_i2_c.html">fabgl::I2C</a>               I2C;</div><div class="line"><a name="_a1"></a><a class="code" href="classfabgl_1_1_s_s_d1306_controller.html">fabgl::SSD1306Controller</a> DisplayController;</div><div class="line"><a name="_a2"></a><a class="code" href="classfabgl_1_1_d_s3231.html">fabgl::DS3231</a>            DS3231;</div><div class="line"><a name="_a3"></a><a class="code" href="classfabgl_1_1_p_s2_controller.html">fabgl::PS2Controller</a>     PS2Controller;</div><div class="line"><a name="_a4"></a><a class="code" href="classfabgl_1_1_terminal.html">fabgl::Terminal</a>          Terminal;</div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">bool</span> dateInvalid;</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">char</span> <span class="keyword">const</span> * encodeDate(<a name="_a5"></a><a class="code" href="structfabgl_1_1_date_time.html">fabgl::DateTime</a> <span class="keyword">const</span> &amp; dt)</div><div class="line">{</div><div class="line">  <span class="keyword">static</span> <span class="keywordtype">char</span> str[11];</div><div class="line">  sprintf(str, <span class="stringliteral">&quot;%02d/%02d/%d&quot;</span>, dt.<a name="a6"></a><a class="code" href="structfabgl_1_1_date_time_a5f0b5de23fa9acb3542c09b4d8e338e6.html#a5f0b5de23fa9acb3542c09b4d8e338e6">dayOfMonth</a>, dt.<a name="a7"></a><a class="code" href="structfabgl_1_1_date_time_a82e68d1d8e1634ac2ba0d01fe0cd95c9.html#a82e68d1d8e1634ac2ba0d01fe0cd95c9">month</a>, dt.<a name="a8"></a><a class="code" href="structfabgl_1_1_date_time_ad2c822e286d2d13dcae4b5f7d8c1049a.html#ad2c822e286d2d13dcae4b5f7d8c1049a">year</a>);</div><div class="line">  <span class="keywordflow">return</span> str;</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">bool</span> decodeDate(<a class="code" href="structfabgl_1_1_date_time.html">fabgl::DateTime</a> * dt, <span class="keywordtype">char</span> <span class="keyword">const</span> * str)</div><div class="line">{</div><div class="line">  <span class="keywordtype">int</span> d, m, y;</div><div class="line">  <span class="keywordflow">if</span> (sscanf(str, <span class="stringliteral">&quot;%02d/%02d/%d&quot;</span>, &amp;d, &amp;m, &amp;y) == 3) {</div><div class="line">    dt-&gt;<a class="code" href="structfabgl_1_1_date_time_a5f0b5de23fa9acb3542c09b4d8e338e6.html#a5f0b5de23fa9acb3542c09b4d8e338e6">dayOfMonth</a> = d;</div><div class="line">    dt-&gt;<a class="code" href="structfabgl_1_1_date_time_a82e68d1d8e1634ac2ba0d01fe0cd95c9.html#a82e68d1d8e1634ac2ba0d01fe0cd95c9">month</a> = m;</div><div class="line">    dt-&gt;<a class="code" href="structfabgl_1_1_date_time_ad2c822e286d2d13dcae4b5f7d8c1049a.html#ad2c822e286d2d13dcae4b5f7d8c1049a">year</a> = y;</div><div class="line">    <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line">  }</div><div class="line">  <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">char</span> <span class="keyword">const</span> * encodeTime(<a class="code" href="structfabgl_1_1_date_time.html">fabgl::DateTime</a> <span class="keyword">const</span> &amp; dt)</div><div class="line">{</div><div class="line">  <span class="keyword">static</span> <span class="keywordtype">char</span> str[9];</div><div class="line">  sprintf(str, <span class="stringliteral">&quot;%02d:%02d:%02d&quot;</span>, dt.<a name="a9"></a><a class="code" href="structfabgl_1_1_date_time_abeadeae0e85f4d556e96cd8548a93c51.html#abeadeae0e85f4d556e96cd8548a93c51">hours</a>, dt.<a name="a10"></a><a class="code" href="structfabgl_1_1_date_time_ab376075e230a393b480cdd45fe454c75.html#ab376075e230a393b480cdd45fe454c75">minutes</a>, dt.<a name="a11"></a><a class="code" href="structfabgl_1_1_date_time_a45bbbde67ef492a5d10a9d519f86984c.html#a45bbbde67ef492a5d10a9d519f86984c">seconds</a>);</div><div class="line">  <span class="keywordflow">return</span> str;</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">bool</span> decodeTime(<a class="code" href="structfabgl_1_1_date_time.html">fabgl::DateTime</a> * dt, <span class="keywordtype">char</span> <span class="keyword">const</span> * str)</div><div class="line">{</div><div class="line">  <span class="keywordtype">int</span> h, m, s;</div><div class="line">  <span class="keywordflow">if</span> (sscanf(str, <span class="stringliteral">&quot;%02d:%02d:%02d&quot;</span>, &amp;h, &amp;m, &amp;s) == 3) {</div><div class="line">    dt-&gt;<a class="code" href="structfabgl_1_1_date_time_abeadeae0e85f4d556e96cd8548a93c51.html#abeadeae0e85f4d556e96cd8548a93c51">hours</a> = h;</div><div class="line">    dt-&gt;<a class="code" href="structfabgl_1_1_date_time_ab376075e230a393b480cdd45fe454c75.html#ab376075e230a393b480cdd45fe454c75">minutes</a> = m;</div><div class="line">    dt-&gt;<a class="code" href="structfabgl_1_1_date_time_a45bbbde67ef492a5d10a9d519f86984c.html#a45bbbde67ef492a5d10a9d519f86984c">seconds</a> = s;</div><div class="line">    <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line">  }</div><div class="line">  <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> inputDateTime()</div><div class="line">{</div><div class="line">  <span class="keyword">auto</span> dt = DS3231.<a name="a12"></a><a class="code" href="classfabgl_1_1_d_s3231_a6eccbc9a02a68038bebb4c9a610b8f7f.html#a6eccbc9a02a68038bebb4c9a610b8f7f">datetime</a>();</div><div class="line"></div><div class="line">  Terminal.<a name="a13"></a><a class="code" href="classfabgl_1_1_terminal_a2da678d7453efcfed190b99ac93a53d0.html#a2da678d7453efcfed190b99ac93a53d0">clear</a>();</div><div class="line">  Terminal.<a name="a14"></a><a class="code" href="classfabgl_1_1_terminal_aace245bfe6cab7b4339bd691077e1c23.html#aace245bfe6cab7b4339bd691077e1c23">enableCursor</a>(<span class="keyword">true</span>);</div><div class="line"></div><div class="line">  <a name="_a15"></a><a class="code" href="classfabgl_1_1_line_editor.html">fabgl::LineEditor</a> LineEditor(&amp;Terminal);</div><div class="line">  LineEditor.setInsertMode(<span class="keyword">false</span>);</div><div class="line"></div><div class="line">  <span class="keywordtype">char</span> <span class="keyword">const</span> * dtstr;</div><div class="line"></div><div class="line">  <span class="keywordflow">do</span> {</div><div class="line">    Terminal.<a name="a16"></a><a class="code" href="classfabgl_1_1_terminal_a7c66fc8d559f4956d4ccea196299bca7.html#a7c66fc8d559f4956d4ccea196299bca7">write</a>(<span class="stringliteral">&quot;Enter Date:\r\n&quot;</span>);</div><div class="line">    LineEditor.setText(encodeDate(dt), <span class="keyword">false</span>);</div><div class="line">    dtstr = LineEditor.edit();</div><div class="line">  } <span class="keywordflow">while</span> (!decodeDate(&amp;dt, dtstr));</div><div class="line"></div><div class="line">  <span class="keywordflow">do</span> {</div><div class="line">    Terminal.<a class="code" href="classfabgl_1_1_terminal_a7c66fc8d559f4956d4ccea196299bca7.html#a7c66fc8d559f4956d4ccea196299bca7">write</a>(<span class="stringliteral">&quot;\nEnter Time:\r\n&quot;</span>);</div><div class="line">    LineEditor.setText(encodeTime(dt), <span class="keyword">false</span>);</div><div class="line">    dtstr = LineEditor.edit();</div><div class="line">  } <span class="keywordflow">while</span> (!decodeTime(&amp;dt, dtstr));</div><div class="line"></div><div class="line">  DS3231.<a name="a17"></a><a class="code" href="classfabgl_1_1_d_s3231_a4b855984a50fd66687dd28acb8c8cb9f.html#a4b855984a50fd66687dd28acb8c8cb9f">setDateTime</a>(dt);</div><div class="line"></div><div class="line">  Terminal.<a class="code" href="classfabgl_1_1_terminal_aace245bfe6cab7b4339bd691077e1c23.html#aace245bfe6cab7b4339bd691077e1c23">enableCursor</a>(<span class="keyword">false</span>);</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> paintClock(Canvas &amp; cv, <a class="code" href="structfabgl_1_1_date_time.html">fabgl::DateTime</a> &amp; dt)</div><div class="line">{</div><div class="line">  <span class="keywordtype">double</span> cx     = 96;</div><div class="line">  <span class="keywordtype">double</span> cy     = 32;</div><div class="line">  <span class="keywordtype">double</span> radius = 42;</div><div class="line"></div><div class="line">  <span class="keywordtype">double</span> pointsRadius  = radius * 0.76;</div><div class="line">  <span class="keywordtype">double</span> secondsRadius = radius * 0.72;</div><div class="line">  <span class="keywordtype">double</span> minutesRadius = radius * 0.60;</div><div class="line">  <span class="keywordtype">double</span> hoursRadius   = radius * 0.48;</div><div class="line"></div><div class="line">  <span class="keywordtype">double</span> s = dt.<a class="code" href="structfabgl_1_1_date_time_a45bbbde67ef492a5d10a9d519f86984c.html#a45bbbde67ef492a5d10a9d519f86984c">seconds</a> / 60.0 * TWO_PI - HALF_PI;</div><div class="line">  <span class="keywordtype">double</span> m = (dt.<a class="code" href="structfabgl_1_1_date_time_ab376075e230a393b480cdd45fe454c75.html#ab376075e230a393b480cdd45fe454c75">minutes</a> + dt.<a class="code" href="structfabgl_1_1_date_time_a45bbbde67ef492a5d10a9d519f86984c.html#a45bbbde67ef492a5d10a9d519f86984c">seconds</a> / 60.0) / 60.0 * TWO_PI - HALF_PI;</div><div class="line">  <span class="keywordtype">double</span> h = (dt.<a class="code" href="structfabgl_1_1_date_time_abeadeae0e85f4d556e96cd8548a93c51.html#abeadeae0e85f4d556e96cd8548a93c51">hours</a> + dt.<a class="code" href="structfabgl_1_1_date_time_ab376075e230a393b480cdd45fe454c75.html#ab376075e230a393b480cdd45fe454c75">minutes</a> / 60.0) / 24.0 * TWO_PI * 2.0 - HALF_PI;</div><div class="line"></div><div class="line">  cv.setPenColor(<a name="a18"></a><a class="code" href="group___enumerations_gab87bacfdad76e61b9412d7124be44c1c.html#ggab87bacfdad76e61b9412d7124be44c1ca3bec3eb0c8a4aab8e31a3a290493ab85">Color::BrightWhite</a>);</div><div class="line">  cv.setPenWidth(3);</div><div class="line">  cv.drawLine(cx, cy, cx + cos(h) * hoursRadius,   cy + sin(h) * hoursRadius);</div><div class="line">  cv.setPenWidth(1);</div><div class="line">  cv.drawLine(cx, cy, cx + cos(s) * secondsRadius, cy + sin(s) * secondsRadius);</div><div class="line">  cv.drawLine(cx, cy, cx + cos(m) * minutesRadius, cy + sin(m) * minutesRadius);</div><div class="line"></div><div class="line"></div><div class="line">  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> a = 0; a &lt; 360; a += 6) {</div><div class="line">    <span class="keywordtype">double</span> arad = radians(a);</div><div class="line">    <span class="keywordtype">double</span> x = cx + cos(arad) * pointsRadius;</div><div class="line">    <span class="keywordtype">double</span> y = cy + sin(arad) * pointsRadius;</div><div class="line">    cv.setPixel(x, y);</div><div class="line">    <span class="keywordflow">if</span> ((a % 15) == 0) {</div><div class="line">      <span class="keywordtype">double</span> x2 = cx + cos(arad) * (pointsRadius - 3);</div><div class="line">      <span class="keywordtype">double</span> y2 = cy + sin(arad) * (pointsRadius - 3);</div><div class="line">      cv.drawLine(x, y, x2, y2);</div><div class="line">    }</div><div class="line">  }</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> setup()</div><div class="line">{</div><div class="line">  Serial.begin(115200); delay(500); Serial.write(<span class="stringliteral">&quot;\n\n\n&quot;</span>); <span class="comment">// DEBUG ONLY  </span></div><div class="line"></div><div class="line">  PS2Controller.<a name="a19"></a><a class="code" href="classfabgl_1_1_p_s2_controller_ab8520612804a921ad834b41214a99c09.html#ab8520612804a921ad834b41214a99c09">begin</a>(PS2Preset::KeyboardPort0);</div><div class="line"></div><div class="line">  I2C.<a name="a20"></a><a class="code" href="classfabgl_1_1_i2_c_abdd72a91fee181ca1b9eb05120e60a28.html#abdd72a91fee181ca1b9eb05120e60a28">begin</a>(OLED_SDA, OLED_SCL);</div><div class="line"></div><div class="line">  DisplayController.<a name="a21"></a><a class="code" href="classfabgl_1_1_s_s_d1306_controller_af4457c33ec3247fb92c8bf2a2d8e9819.html#af4457c33ec3247fb92c8bf2a2d8e9819">begin</a>(&amp;I2C, OLED_ADDR, OLED_RESET);</div><div class="line">  DisplayController.<a name="a22"></a><a class="code" href="classfabgl_1_1_s_s_d1306_controller_a2ac60f74ade23bfba42ef0985635589d.html#a2ac60f74ade23bfba42ef0985635589d">setResolution</a>(OLED_128x64);</div><div class="line"></div><div class="line">  <span class="keywordflow">while</span> (!DisplayController.<a name="a23"></a><a class="code" href="classfabgl_1_1_s_s_d1306_controller_a4a47f12debf6d5d7273c3e5fb360417a.html#a4a47f12debf6d5d7273c3e5fb360417a">available</a>()) {</div><div class="line">    Serial.write(<span class="stringliteral">&quot;Error, SSD1306 not available!\n&quot;</span>);</div><div class="line">    delay(5000);</div><div class="line">  }</div><div class="line"></div><div class="line">  Terminal.<a name="a24"></a><a class="code" href="classfabgl_1_1_terminal_aebaecc1fa474fddc48dd5778024b19a5.html#aebaecc1fa474fddc48dd5778024b19a5">begin</a>(&amp;DisplayController);</div><div class="line">  Terminal.<a name="a25"></a><a class="code" href="classfabgl_1_1_terminal_a068123b964647130439aa949370181dc.html#a068123b964647130439aa949370181dc">connectLocally</a>();</div><div class="line">  Terminal.<a name="a26"></a><a class="code" href="classfabgl_1_1_terminal_a72770033c3a06f499a251909efba87c7.html#a72770033c3a06f499a251909efba87c7">loadFont</a>(&amp;fabgl::FONT_8x8);</div><div class="line"></div><div class="line">  Canvas cv(&amp;DisplayController);</div><div class="line">  cv.clear();</div><div class="line"></div><div class="line">  DS3231.<a name="a27"></a><a class="code" href="classfabgl_1_1_d_s3231_acd45c96e11bf7479f3a75d4cd4975878.html#acd45c96e11bf7479f3a75d4cd4975878">begin</a>(&amp;I2C);</div><div class="line">  <span class="keywordflow">while</span> (!DS3231.<a name="a28"></a><a class="code" href="classfabgl_1_1_d_s3231_a4a47f12debf6d5d7273c3e5fb360417a.html#a4a47f12debf6d5d7273c3e5fb360417a">available</a>()) {</div><div class="line">    Serial.write(<span class="stringliteral">&quot;DS3231 not available!\n&quot;</span>);</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="comment">// uncomment to forget date/time on powerloss</span></div><div class="line">  <span class="comment">//DS3231.clockEnabled(false);</span></div><div class="line"></div><div class="line">  dateInvalid = !DS3231.<a name="a29"></a><a class="code" href="classfabgl_1_1_d_s3231_a94e15947dfbd16e4f6ef6f4fe0b7ae49.html#a94e15947dfbd16e4f6ef6f4fe0b7ae49">dateTimeValid</a>();</div><div class="line">  <span class="keywordflow">if</span> (dateInvalid &amp;&amp; PS2Controller.<a name="a30"></a><a class="code" href="classfabgl_1_1_p_s2_controller_ab7bbbedef758e471e6eb693acfb17c33.html#ab7bbbedef758e471e6eb693acfb17c33">keyboard</a>()-&gt;<a name="a31"></a><a class="code" href="classfabgl_1_1_keyboard_aef1dd1399d92a09d1ed115911b563688.html#aef1dd1399d92a09d1ed115911b563688">isKeyboardAvailable</a>()) {</div><div class="line">    <span class="comment">// date/time invalid, request user to insert new datetime</span></div><div class="line">    inputDateTime();</div><div class="line">  }</div><div class="line"></div><div class="line">  cv.clear();</div><div class="line"></div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> loop()</div><div class="line">{</div><div class="line">  <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> * D2S[] = { <span class="stringliteral">&quot;Sun&quot;</span>, <span class="stringliteral">&quot;Mon&quot;</span>, <span class="stringliteral">&quot;Tue&quot;</span>, <span class="stringliteral">&quot;Wed&quot;</span>, <span class="stringliteral">&quot;Thu&quot;</span>, <span class="stringliteral">&quot;Fri&quot;</span>, <span class="stringliteral">&quot;Sat&quot;</span> };</div><div class="line">  <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> * M2S[] = { <span class="stringliteral">&quot;Jan&quot;</span>, <span class="stringliteral">&quot;Feb&quot;</span>, <span class="stringliteral">&quot;Mar&quot;</span>, <span class="stringliteral">&quot;Apr&quot;</span>, <span class="stringliteral">&quot;May&quot;</span>, <span class="stringliteral">&quot;Jun&quot;</span>, <span class="stringliteral">&quot;Jul&quot;</span>, <span class="stringliteral">&quot;Aug&quot;</span>, <span class="stringliteral">&quot;Sep&quot;</span>, <span class="stringliteral">&quot;Oct&quot;</span>, <span class="stringliteral">&quot;Nov&quot;</span>, <span class="stringliteral">&quot;Dec&quot;</span> };</div><div class="line"></div><div class="line">  <span class="keyword">auto</span> dt = DS3231.<a class="code" href="classfabgl_1_1_d_s3231_a6eccbc9a02a68038bebb4c9a610b8f7f.html#a6eccbc9a02a68038bebb4c9a610b8f7f">datetime</a>();</div><div class="line"></div><div class="line">  Canvas cv(&amp;DisplayController);</div><div class="line">  cv.beginUpdate();</div><div class="line">  cv.clear();</div><div class="line">  cv.selectFont(&amp;fabgl::FONT_std_15);</div><div class="line">  cv.drawTextFmt(0, 0, <span class="stringliteral">&quot;%s, %s %d&quot;</span>, D2S[dt.<a name="a32"></a><a class="code" href="structfabgl_1_1_date_time_acb1264377521faab9e0ede2a086ba956.html#acb1264377521faab9e0ede2a086ba956">dayOfWeek</a>-1], M2S[dt.<a class="code" href="structfabgl_1_1_date_time_a82e68d1d8e1634ac2ba0d01fe0cd95c9.html#a82e68d1d8e1634ac2ba0d01fe0cd95c9">month</a> - 1], dt.<a class="code" href="structfabgl_1_1_date_time_a5f0b5de23fa9acb3542c09b4d8e338e6.html#a5f0b5de23fa9acb3542c09b4d8e338e6">dayOfMonth</a>);</div><div class="line">  cv.drawTextFmt(13, 18, <span class="stringliteral">&quot;%d&quot;</span>, dt.<a class="code" href="structfabgl_1_1_date_time_ad2c822e286d2d13dcae4b5f7d8c1049a.html#ad2c822e286d2d13dcae4b5f7d8c1049a">year</a>);</div><div class="line"></div><div class="line">  cv.selectFont(&amp;fabgl::FONT_std_12);</div><div class="line">  cv.drawTextFmt(78, 44, <span class="stringliteral">&quot;%s&quot;</span>, encodeTime(dt));</div><div class="line"></div><div class="line">  cv.selectFont(&amp;fabgl::FONT_std_17);</div><div class="line">  cv.setGlyphOptions(GlyphOptions().<a name="a33"></a><a class="code" href="displaycontroller_8h_ad03f06d4f3e36a9e80bd239d29fdb458.html#ad03f06d4f3e36a9e80bd239d29fdb458">Bold</a>(<span class="keyword">true</span>));</div><div class="line">  cv.drawTextFmt(4, 44, <span class="stringliteral">&quot;%0.1f \xb0 C&quot;</span>, DS3231.<a name="a34"></a><a class="code" href="classfabgl_1_1_d_s3231_a014e16702b5d223dd46cda87bfb8318b.html#a014e16702b5d223dd46cda87bfb8318b">temperature</a>());</div><div class="line">  cv.resetGlyphOptions();</div><div class="line"></div><div class="line"></div><div class="line">  paintClock(cv, dt);</div><div class="line"></div><div class="line">  cv.endUpdate();</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> (Terminal.<a name="a35"></a><a class="code" href="classfabgl_1_1_terminal_a4549a76725f2e4c013e4d57018366109.html#a4549a76725f2e4c013e4d57018366109">available</a>()) {</div><div class="line">    <span class="keywordtype">char</span> c = Terminal.<a name="a36"></a><a class="code" href="classfabgl_1_1_terminal_aaab5dab5b969a87f538242e524431637.html#aaab5dab5b969a87f538242e524431637">read</a>();</div><div class="line">    <span class="keywordflow">if</span> (c == 0x0d) {</div><div class="line">      <span class="comment">// ENTER, set date/time</span></div><div class="line">      inputDateTime();</div><div class="line">    }</div><div class="line">  }</div><div class="line"></div><div class="line">  delay(1000);</div><div class="line"></div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Wed Dec 9 2020 16:48:29 for FabGL by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.14 </li>
  </ul>
</div>
</body>
</html>
